const Ws=require('ws');

;((Ws)=>{
const server=new Ws.Server({port:8000});
const init=()=>{
bindEvent();
}
function bindEvent(){
    server.on('open',handleOpen);
    server.on('close',handleClose);
    server.on('error',handleError);
    server.on('connection',handleConnection);
}
function handleOpen(){
    console.log('server open');
}
function handleClose(){
    console.log('server close');
}
function handleError(){
    console.log('server error');
}
function handleConnection(ws){
    console.log('server connected');
    ws.on('message',handleMessage);
}
function handleMessage(msg){
server.clients.forEach((c)=>{
    c.send(msg.toString());
})
}


init();
})(Ws);